package com.goods.controller.business;

import com.goods.business.service.BizSupplierService;
import com.goods.common.model.business.BizProductCategory;
import com.goods.common.model.business.BizSupplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.google.common.base.Suppliers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/business/supplier")
public class SupplierController {
    @Autowired
    private BizSupplierService bizSupplierService;

    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam int pageNum,@RequestParam int pageSize, @RequestParam String name,
                                        @RequestParam String address,@RequestParam String contact){
        List<SupplierVO> supplierVOList=bizSupplierService.selectPage(pageNum,pageSize,name,address,contact);
        HashMap<String, Object> resultMap= new HashMap<>();
        resultMap.put("total",supplierVOList.size());
        resultMap.put("rows",supplierVOList);
        return ResponseBean.success(resultMap);
    }
    @PostMapping("add")
    public  ResponseBean add(@RequestBody BizSupplier bizSupplier){
        bizSupplierService.add(bizSupplier);
        return ResponseBean.success();
    }
    @GetMapping("edit/{id}")
    public ResponseBean edit(@PathVariable long id){
        BizSupplier bizSupplier=bizSupplierService.findById(id);
        return ResponseBean.success(bizSupplier);
    }
    @PutMapping("update/{id}")
    public ResponseBean update(@RequestBody BizSupplier bizSupplier){
       bizSupplierService.update(bizSupplier);
       return ResponseBean.success();
    }
    @DeleteMapping("delete/{id}")
    public ResponseBean delete(@PathVariable long id) {
        bizSupplierService.deleteById(id);
        return ResponseBean.success();
    }
}
